<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}"><!-- 不用base就使用th:src="@{/js/jquery.min.js} -->
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <base th:href="@{/}">
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
    <script th:inline="javascript">

        function checkPhoneNumber() {
            if (checkNull($("#phoneNumber").val(), "请输入手机号！")) {
                $.ajax(
                    {//提交检查用户名是否可用请求
                        //请求路径，要注意的是url和th:inline="javascript"
                        url: [[@{/user/isUse
                    }
            ]],
                //请求类型
                type : "post",
                    contentType
            :
                "application/json",
                    //data表示发送的数据
                    data
            :
                JSON.stringify({
                    phoneNumber: $("#phoneNumber").val()
                }),
                    //成功响应的结果
                    success
            :

                function (obj) {//obj响应数据
                    if (obj == "no") {
                        $("#isExit").html("<font color=red size=5>×</font>");
                        alert("用户已存在，请修改！");
                    } else {
                        $("#isExit").html("<font color=green size=5>√</font>");
                        alert("用户可用");
                    }
                }

            ,
                error : function () {
                    alert("处理异常！");
                }
            }
            )
                ;
            }
        }

        function checkBpwd() {
            if ($("#bpwd").val() != $("#rebpwd").val()) {
                alert("两次密码不一致！");
                return false;
            }
            document.myform.submit();
        }

        function sendMessage() {
            var phoneNumber = $("#phoneNumber").val()
            alert(phoneNumber)
            $.ajax({
                url: "user/send/message",
                type: "post",
                data: {
                    "phoneNumber": phoneNumber
                },
                dataType: "json",
                success: function (response) {
                    // 返回的result为SUCCESS
                    if (response.result == "SUCCESS") {
                        alert("发送成功！")
                    }
                    // 返回的result为FAILED
                    if (response.result == "FAILED")
                        alert("发送失败！")
                },
                error: function (response) {
                    alert("statusCode=" + response.status + " message=" + response.statusText);
                }

            });

        }
    </script>
    <style>
        body {
            /* 设置背景渐变 */
            background-image: linear-gradient(to left,
            #9c88ff, #3cadeb);
            display: flex;
            justify-content: center;
        }

        .a {
            position: relative;
            top: 100px;
            width: 1100px;
            height: 550px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, .8);
            display: flex;
        }

        .b {
            width: 750px;
            height: 550px;
            /*background-image: url("");*/
            /* 让图片适应大小 */
            background-size: cover;
        }

        .c {
            width: 350px;
            height: 550px;
            background-color: white;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .d {
            width: 250px;
            height: 500px;
        }

        .d h1 {
            font: 900 30px '';
        }

        .e {
            width: 230px;
            margin: 7px 0;
            outline: none;
            border: 0;
            padding: 10px;
            border-bottom: 3px solid rgb(80, 80, 170);
            font: 900 16px '';
        }

        .f {
            float: right;
            margin: 10px 0;
        }

        .g {
            position: absolute;
            margin: 20px;
            bottom: 40px;
            display: block;
            width: 100px;
            height: 60px;
            font: 900 30px '';
            text-decoration: none;
            line-height: 50px;
            border-radius: 30px;
            background-image: linear-gradient(to left,
            #9c88ff, #3cadeb);
            text-align: center;
        }

        .h {
            position: absolute;
            margin: 8px;
            bottom: 53px;
            left: 970px;
            display: block;
            width: 100px;
            height: 60px;
            font: 900 30px '';
            text-decoration: none;
            line-height: 50px;
            border-radius: 30px;
            background-image: linear-gradient(to left, #9c88ff, #3cadeb);
            text-align: center;
        }

        .pic {
            width: 750px;
            height: 550px;
        }
    </style>
    <script type="text/javascript" th:inline="javascript">
        function refreshCode() {
            document.getElementById("mycode").src = [[@{/validateCode}]] + "?t=" + Math.random();
        }
    </script>
</head>
<body>
    <div class="a">
        <div class="b"><img class="pic" th:src="'images/' + 'swu.jpg'"></div>
        <form action="user/register" name="myform" method="post" th:object="${bUser}">
            <div class="c">
                <div class="d">
                    <h1>用户注册</h1>
                    <input type="text" class="e" placeholder="请输入您的手机号" th:field="*{phoneNumber}"
                           onblur="checkPhoneNumber()">
                    <span id="isExit"></span>

                    <input type="password" class="e" placeholder="请输入您的密码" th:field="*{bpwd}">
                    <span th:errors="*{bpwd}"></span>

                    <input type="password" class="e" placeholder="请确认您的密码" th:field="*{rebpwd}">
                    <input class="e" type="text" style="width: 170px;" placeholder="验证码" th:field="*{code}"
                           id="registerCode">
                    <a href="javascript:refreshCode()"><img th:src="@{/validateCode}" id="mycode"></a>

                    <input type="text" style="width: 170px;" class="e" placeholder="请输入短信验证码" th:field="*{messageCode}">
                    <a href="javascript:;" onclick="sendMessage() " style="text-decoration: none">获取验证码</a>
                    <!--<input type="button" value="获取信验证码" onclick="sendMessage() ">-->

                </div>
            </div>
            <button type="submit" class="g">注册</button>
            <button class="h" type="reset">重置</button>
        </form>
    </div>
</body>
</html>